//
//  Server.Path.swift
//  API
//
//  Created by ET|冰琳 on 2017/3/23.
//  Copyright © 2017年 IB. All rights reserved.
//

import Foundation

// MARK: - Server
struct Server {
    
    // eg: http https ...
    let scheme: String
    
    // eg: api.github.com
    let host: String
    
    // eg: "/user"
    let basePath: String
    
    fileprivate var url: String {
        let urlString = "\(scheme)://\(host)\(basePath)"
        return urlString
    }
}

extension Server {
    
    func urlString(_ path: Path) -> String {
        return self.url + path.rawValue
    }
    
    func url(_ path: Path) -> URL? {
        return URL(string: self.url)?.appendingPathComponent(path.rawValue)
    }    
}

// MARK: - path
struct Path: ExpressibleByStringLiteral {
    
    var rawValue: String
    
    public init(path: String) {
        self.rawValue = path
    }
    
    public init(stringLiteral value: String){
        rawValue = value
    }
    
    public init(unicodeScalarLiteral value: String){
        rawValue = value
    }
    
    public init(extendedGraphemeClusterLiteral value: String){
        rawValue = value
    }
}
